/**
 * Copyright (c) 2012-3-25, lysong01@gmail.com. All rights reserved.
 * 牌只有1到9，手里拿着已经排好序的牌a，对方出牌b，用程序判断手中牌是否能够压过对方出牌 
规则：出牌牌型有5种   
[1]一张 如4 则5...9可压过 
[2]两张 如44 则55，66，77，...，99可压过 
[3]三张 如444 规则如[2] 
[4]四张 如4444 规则如[2] 
[5]五张 牌型只有12345 23456 34567 45678 56789五个，后面的比前面的均大 
 
压过输出YES 否则NO 

如(括号内容为注释) 
输入： 
12233445566677(手中牌) 
33(出牌) 
 
输出： 
YES
 */
package bupt.wangyan;

import java.util.Scanner;

/**
 * @author  liyasong
 * @version %I%, %G%
 * @since   liyasong1.0
 */
public class Pro2010_3 {

	/**
	 * @param args
	 * void
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sca = new Scanner(System.in);
		String handCard = sca.next();
		String outCard = sca.next();
		int k = outCard.charAt(0) - '1';
		int outLen = outCard.length();
		int [] count = new int[9];
		boolean able = false;
		/*
		 * 很巧妙的方法，将数组当成map用
		 */
		for (int i = 0; i < handCard.length(); i++) {
			int temp = handCard.charAt(i) - '1';
			count[temp]++;
		}
		if (outLen < 5) {
			for (int i = k+1; i < count.length; i++) {
				if (count[i] >= outLen) {
					able = true;
					break;
				}
			}
		} else {
			for (int i = k+1; i < count.length-4; i++) {	//
				if (count[i]!=0 && count[i+1]!=0 &&
						count[i+2]!=0 && count[i+3]!=0 && count[i+4]!=0) {
					able = true;
				}
			}
		}
		System.out.println(able ? "YES":"NO");
	}

}
